package com.example.zyfypt_206shj.fragement;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.zyfypt_206shj.R;
import com.example.zyfypt_206shj.adapter.VideoAdapter;
import com.example.zyfypt_206shj.bean.SessionID;
import com.example.zyfypt_206shj.bean.UserInfo;
import com.example.zyfypt_206shj.bean.VideoBean;
import com.example.zyfypt_206shj.iface.VideoListener;
import com.example.zyfypt_206shj.model.VideoModel;

import java.util.List;


/**
 * Created by Neusoft on 2017/4/9.
 */

public class Fragment4 extends Fragment {
    private View view=null;
    private Context context;
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private VideoAdapter videoAdapter;
    private List<VideoBean> list=null;
    private VideoListener videoListener = new VideoListener() {
        @Override
        public void onResponse(List<VideoBean> beanlist) {
            list = beanlist;
            videoAdapter.setList(list);
            videoAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context, "fail" + msg, Toast.LENGTH_SHORT).show();
        }
    };
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        context=getActivity();
        //动态加载Fragment的布局文件
        view=inflater.inflate(R.layout.fragment4,container,false);
        //获取布局上的控件，注意通过view获取
        //返回动态生成的view
        initRecyclerView();
        VideoModel videoModel = new VideoModel();
        videoModel.getResultList("video", 1, SessionID.sessionID, videoListener);
        return view;
    }
    private void initRecyclerView(){
        layoutManager = new LinearLayoutManager(getContext());

        recyclerView=(RecyclerView)view.findViewById(R.id.recyclerView4);
        //创建默认线性布局
        recyclerView.setLayoutManager(layoutManager);
        //固定每个item的高度，可以提高性能
        recyclerView.setHasFixedSize(true);
        //获取数据
        //list=getData();
        //实例化adapter
        videoAdapter=new VideoAdapter(getContext());
        videoAdapter.setList(list);
        recyclerView.setAdapter(videoAdapter);
    }
}
